#ifndef __SL3D_H__
#define __SL3D_H__

#ifdef __cplusplus
extern "C" {
#endif

#include <stdint.h>
#include <stdbool.h>

typedef enum  {
    TRP_SAD_WIN_SIZE_9  = 9, 	 /**< 9  */
    TRP_SAD_WIN_SIZE_11 = 11,    /**< 11 */
    TRP_SAD_WIN_SIZE_13 = 13,    /**< 13 */
    TRP_SAD_WIN_SIZE_15 = 15,    /**< 15 */
    TRP_SAD_WIN_IDX_MAX
}tsmTRP_SADWin;

typedef enum {
	TRP_SL3D_DEBUG_SOBEL_MODULE,          /**< type: int32 */
	TRP_SL3D_DEBUG_SAD_MODULE,            /**< type: int16 */
	TRP_SL3D_DEBUG_DP_CPD_MODULE,         /**< type: int32 */
	TRP_SL3D_DEBUG_DP_SPD_MODULE,         /**< type: int32 */
	TRP_SL3D_DEBUG_DP_DIFSUM_SPD_MODULE,  /**< type: int32 */
	TRP_SL3D_DEBUG_REC_MODULE,            /**< type: uint8 */
	TRP_SL3D_DEBUG_MAX_MODULE
} tsmTRP_Sl3dDebugModule;

typedef struct
{
    int             h;
    int             w;
    int             minDisparity;      /*< default 12 */
    tsmTRP_SADWin   SADWindowSize;     /*< default 13 */
    int             rectifyEnable;
}tsmTRP_SgbmBase;

typedef struct
{
   uint16_t 		p1;
   uint16_t			p2;
}tsmTRP_SgbmDynamicPlan;

typedef struct
{
    int     h;
    int     w;
    void    *  leftFXY;
    void    *  rightFXY;
    void    *  leftXY;
    void    *  rightXY;
    void    *  weight;
}tsmTRP_SgbmRectify;

typedef struct
{
	int 	speckle_is_16bit;
    int     preFilterCap;
    int     originalWeight;
    int     weight;
}tsmTRP_SgbmSobel;

typedef struct
{
    int     disp12MaxDiff;
    float   uniquenessRatio;
}tsmTRP_SgbmUnique;


typedef enum
{
	TRP_DISP_RANGE_NEG_1_63 = 0, /**< -1~63 */
	TRP_DISP_RANGE_NEG_4_252,    /**< -4~255 */
	TRP_DISP_RANGE_NEG_16_1008,  /**< -16~1008 */
	TRP_DISP_RANGE_NEG_32_8160,  /**< -32~8160 */
	TRP_DISP_RANGE_0_255         /**< 0~255 */
 }tsmTRP_DispRange;

typedef struct
{
	tsmTRP_DispRange     dispRange;
    int     		speckleWindowSize;
}tsmTRP_SgbmSpeck;

typedef struct
{
    float     distanceToTarget;			/* set 0 use default */
    float     distanceBetweenCameras;	/* set 0 use default */
    float     foucs;					/* set 0 use default */
    float     x_offset;    				 /*< speckle input offset, left < 0 */
}tsmTRP_SgbmDepthMap;

typedef struct
{
    int32_t                 use_double_eye;
    int32_t                 left_base_mode;
    tsmTRP_SgbmBase         base;
    tsmTRP_SgbmDynamicPlan	dynamic_plan;
    tsmTRP_SgbmRectify      rectify;
    tsmTRP_SgbmSobel        sobel;
    tsmTRP_SgbmUnique       unique;
    tsmTRP_SgbmSpeck        speck;
    tsmTRP_SgbmDepthMap     depth;
	tsmTRP_Sl3dDebugModule  debug_module;  /* default : SL3D_MAX_MODULE */
}tsmTRP_Sl3dCfg_t;

typedef enum 
{
    TRP_IMG_SHIFT_RIGHT,
    TRP_IMG_SHIFT_LEFT,
    TRP_IMG_PAD_RIGHT,
    TRP_IMG_PAD_LEFT,
    TRP_IMG_PRE_NONE,
}tsmTRPSl3d_ImgPreMode_e;

typedef struct
{
	uint8_t *left;
	uint8_t *right;
	int16_t *disp;
	int16_t *depth;
	int32_t *debug_out;    /**< debug output */
    int h_left;
    int w_left;
    tsmTRPSl3d_ImgPreMode_e   pre_mode;
	int flag;
    uint8_t *ir;
	int guidefilter_en;
}tsmTRP_Sl3dData_t;

typedef struct
{
	int ret;
	uint8_t *depth;
}tsmTRP_Sl3dRet_t;


typedef struct
{
	void * cfg1;		/*< closest  base */
	void * cfg2;		/*< farthest base */

	uint8_t * base1;
	uint8_t * base2;
	uint8_t * speckle;

	uint32_t dist;					/* depth selection distance unit:mm */
	int32_t  min_valid_value1;
	int32_t  max_valid_value1;
	int32_t  min_valid_value2;
	int32_t  max_valid_value2;
}tsmTRP_Sl3dData_Base2_t;


#define  SL3D_INPUT_H 360
#define  SL3D_INPUT_W 640


void ipcInitSl3dDepth_SingleEye(void *data);
void * ipcRunSl3dDepth_SingleEye(void *data);
void * ipcRunSl3dDisp_SingleEye(void *data);
void * ipcRunSl3dDepth_SingleEye_2base(void * data);


#ifdef __cplusplus
}
#endif

#endif
